<template>
  <div>
    <!-- 已登录头部 -->
    <div class="My_title" v-if="isShow">
      <img
        style="width: 100%"
        src="@/assets/9b336ca6d933c895c9cfa752d61373f082020079.jpg"
        alt=" 背景图"
      />
      <div class="My_info">
        <div class="My_myIcon">
          <img
            style="width: 100%; border-radius: 50%"
            src="../../assets/微信图片_20220531095952.jpg"
            alt="icon"
          />
        </div>
        <div style="padding-top: 15px">
          <div style="margin: -30px 0 10px 0">東雲研究所</div>
          <div>
            <van-button
              color="#21b97a"
              size="small"
              @click="logout"
              style="border-radius: 5px"
              >退出登录</van-button
            >
          </div>
        </div>
      </div>
    </div>

    <!-- 未登录头部 -->
    <div class="My_title" v-else>
      <img
        style="width: 100%"
        src="http://liufusong.top:8080/img/profile/bg.png"
        alt=" 背景图"
      />
      <div class="My_info">
        <div class="My_myIcon">
          <img
            style="width: 100%; border-radius: 50%"
            src="http://liufusong.top:8080/img/profile/avatar.png"
            alt="icon"
          />
        </div>
        <div style="padding-top: 15px">
          <div style="margin: -30px 0 10px 0">游客</div>
          <div>
            <van-button
              color="#21b97a"
              size="small"
              to="/login"
              style="border-radius: 5px"
              >去登录</van-button
            >
          </div>
        </div>
      </div>
    </div>

    <!-- 中间部分 -->
    <div style="margin-top: 10px">
      <van-grid clickable :column-num="3">
        <van-grid-item icon="star-o" text="我的收藏" @click="toFavorate" />
        <van-grid-item icon="home-o" text="我的出租" @click="toMyHouse" />
        <van-grid-item icon="clock-o" text="看房记录" />
        <van-grid-item icon="shop-collect-o" text="成为房主" />
        <van-grid-item icon="manager-o" text="个人资料" />
        <van-grid-item icon="service-o" text="联系我们" />
      </van-grid>
    </div>

    <!-- 下侧广告 -->
    <div class="My_ad">
      <img
        style="width: 90%"
        src="http://liufusong.top:8080/img/profile/join.png"
        alt=""
      />
    </div>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {};
  },
  components: {},
  computed: {
    isShow() {
      return !!this.$store.state.tokenLogin.token;
    },
  },
  methods: {
    logout() {
      this.$dialog
        .confirm({
          title: "提示",
          message: "确定退出登录？",
        })
        .then(() => {
          // on confirm
          this.$store.commit("SET_TOKEN", "");
        })
        .catch(() => {
          // on cancel
        });
    },
    toFavorate() {
      if (!this.isShow) {
        this.$router.push("/login");
        return;
      }
      this.$router.push("/favorate");
    },
    toMyHouse() {
      if (!this.isShow) {
        this.$router.push("/login");
        return;
      }
      this.$router.push("/myhouse");
    },
  },
};
</script>
<style scoped>
.My_title {
  min-height: 300px;
  position: relative;
}
.My_info {
  position: absolute;
  background: #fff;
  width: 70%;
  height: 55%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;
  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
  border-radius: 10px;
}
.My_myIcon {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.My_ad {
  text-align: center;
  margin-top: 10px;
}
</style>
